package com.qhy.wxpay.controller;

import com.qhy.wxpay.service.CourseService;
import com.qhy.wxpay.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/api")
public class IndexController {

    @Autowired
    CourseService courseService;

    /**
     * 跳转课程首页
     * @return
     */
    @GetMapping("index")
    public String index() {
        return "index";
    }


    /**
     * 查询所有课程
     * @return
     */
    @ResponseBody
    @GetMapping("/loadcourse")
    public R loadCourse() {
        return R.ok().data("courses", courseService.list());
    }

    /**
     * 跳转课程明细
     * @param id
     * @param modelMap
     * @return
     */
    @GetMapping("coursedetail/{id}")
    public String coursedetail(@PathVariable("id")String id, ModelMap modelMap){
        modelMap.put("course",courseService.getById(id));
        return "coursedetail";
    }
}
